package com.wsd.bookkeeping.controller;

import com.wsd.bookkeeping.service.AccountStatisticService;
import com.wsd.common.entity.ResponseEntity;
import com.wsd.common.utils.Pair;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;

@RestController
@RequestMapping("/static")
public class AccountStatisticController {

    @Resource
    private AccountStatisticService accountStatisticService;

    /**
     * 获取账本12月的消费情况
     * @param bookId 账本Id
     * @param year 要查询的年份
     */
    @GetMapping("/{bookId}/{year}")
    @SuppressWarnings("")
    public ResponseEntity getAccountMonthRangeAmount(@PathVariable Integer bookId, @PathVariable Integer year) throws InterruptedException {
        Pair<Map<Integer, BigDecimal>, Map<Integer, BigDecimal>> pair = accountStatisticService.getAccountMonthRangeAmount(bookId, year);
        return ResponseEntity.success().put("income", pair.getLeft()).put("outcome", pair.getRight());
    }

}
